#include "HelloWorldScene.h"
#include "Sudoku.h"

USING_NS_CC;

CCScene* HelloWorld::scene()
{
    // 'scene' is an autorelease object
    CCScene *scene = CCScene::create();
    
    // 'layer' is an autorelease object
    HelloWorld *layer = HelloWorld::create();

    // add layer as a child to scene
    scene->addChild(layer);

    // return the scene
    return scene;
}

// on "init" you need to initialize your instance
bool HelloWorld::init()
{
    //////////////////////////////
    // 1. super init first
    if ( !CCLayer::init() )
    {
        return false;
    }       
    
	CCEGLView::sharedOpenGLView()->setDesignResolutionSize(480, 852, kResolutionShowAll);
	int** sudoku = Sudoku::GenerateSudoku();
	for (size_t i = 0; i < 9; i++)
	{	
		CCLOG("%d %d %d    %d %d %d    %d %d %d\n", 
			sudoku[i][0], 
			sudoku[i][1], 
			sudoku[i][2], 
			sudoku[i][3], 
			sudoku[i][4], 
			sudoku[i][5], 
			sudoku[i][6], 
			sudoku[i][7], 
			sudoku[i][8]);
	}

	CCSprite *bg = CCSprite::create("slice48_48.png");
	addChild(bg);
	bg->setPosition(ccp(240, 426));	

	for (int i = 0; i < 9; i++)
	{
		for (int j = 0; j < 9; j++)
		{
			CCLabelTTF *lab = CCLabelTTF::create(CCString::createWithFormat("%d", sudoku[i][j])->getCString(), "Arial", 32);
			lab->setColor(ccc3(0, 0, 0));
			bg->addChild(lab);
			lab->setPosition(ccp(i * 49.0f + 25.0f, j * 49.0f + 25.0f));
		}
	}

    return true;
}


void HelloWorld::menuCloseCallback(CCObject* pSender)
{
#if (CC_TARGET_PLATFORM == CC_PLATFORM_WINRT) || (CC_TARGET_PLATFORM == CC_PLATFORM_WP8)
	CCMessageBox("You pressed the close button. Windows Store Apps do not implement a close button.","Alert");
#else
    CCDirector::sharedDirector()->end();
#if (CC_TARGET_PLATFORM == CC_PLATFORM_IOS)
    exit(0);
#endif
#endif
}
